var cookie = JSON.parse($.cookie('bjou_student'));
jQuery(document).ready(function($) {
	$.ajax({
		type: 'GET',
		url: 'api/v1/check'

	}).done(function (data, textStatus, jqXHR) {

	}).fail(function (jqXHR, textStatus, errorThrown) {
        window.location = '../index.html';
	});
    $('#welcome').html("欢迎," + cookie.studentName + "同学")
	$('#logout').on('click', function (event) {
		event.preventDefault();
		$.ajax({
			data: {},
			timeout: 1000,
			type: 'POST',
			url: '../logout'

		}).done(function(data, textStatus, jqXHR) {
			window.location = '../index.html';
		}).fail(function(jqXHR, textStatus, errorThrown) {
		    window.location = '../index.html';
		});
	});

});

var getStudentScoreUrl = 'api/v1/score/current/' + cookie.studentID;
var getStudentScoreOptions = {
    elem: '#StudentScore',
    url: getStudentScoreUrl,
    method: 'POST',
    contentType: 'application/json',
    id: 'studentCurrentScoreTable',
    page: true,
    limit: 20,
    loading: true,
    cols: [[
        {type:'numbers', title:'序号', width: 50}
        , {field:'kcmc', title:'课程名称'}
        , {field:'kscs', title:'考试次数'}
        , {field:'qdcjsj', title:'考试时间', sort: true}
        , {field:'xkcj', title:'形考成绩'}
        , {field:'sjcj', title:'卷面成绩'}
        , {field:'zhcj', title:'综合成绩'}
        , {field:'pass', title:'状态', sort: true}

    ]],
    request: {
        limitName: 'size'
    },
    response: {
        statusName: null,
        statusCode: null,
        countName: 'totalElements',
        dataName: 'content'
    }
};
layui.use(['table', 'element', 'form'], function(){
    var $ = layui.jquery
    ,table = layui.table
    ,form = layui.form
    ,element = layui.element;

    form.on('radio(cj_radio)', function(data){
        table.reload('studentCurrentScoreTable', {
            url: 'api/v1/score/'+ data.value +'/' + cookie.studentID
        })
    });
    table.render(getStudentScoreOptions);

});
